﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArgusPCLib.Mathematics
{
	class Variable : IOperand
	{
		IOperand _value;
		public string Name { get; private set; }
		public Type ValueType { get; private set; }
		public IOperand Value
		{
			get { return this._value; }
			set
			{
				if (value != null && !value.GetType().Is(this.ValueType))
					throw new ArgumentException(string.Format(Resources.Exceptions.InvalidType, "Value", this.ValueType));
				this._value = value;
			}
		}
		public bool HasValue { get { return this.Value != null; } }

		public Variable(string name, Type valueType, IOperand value)
		{
			this.Name = name;
			this.ValueType = valueType;
			this.Value = value;
		}

		public Variable(string name, Type valueType)
			: this(name, valueType, null) { }

		public Variable(string name)
			: this(name, typeof(IOperand)) { }

		#region IOperand
		public static Variable Parse(string text, string format, IFormatProvider formatProvider)
		{
			throw new NotImplementedException();
		}

		public static bool TryParse(string text, string format, IFormatProvider formatProvider, out Variable value)
		{
			throw new NotImplementedException();
		}

		public static int PartialParse(string text, string format, IFormatProvider formatProvider, out Variable value)
		{
			throw new NotImplementedException();
		}

		public Variable GetDeepCopy()
		{
			return new Variable(this.Name, this.ValueType, this.Value);
		}

		IOperand IOperand.GetDeepCopy() { return this.GetDeepCopy(); }

		// string IFormattable.ToString(string format, IFormatProvider formatProvider)
		public string ToString(string format, IFormatProvider formatProvider)
		{
			if (this.HasValue)
				return this.Name+'='+this.Value.ToString();
			return this.Name;
		}
		#endregion
	}
}
